from enum import IntEnum, auto

_token_name_map = {}

class TokenType(IntEnum):
    DEFINE = auto()  # 定义关键字
    LAMBDA = auto()  # Lambda关键字
    QUOTE = auto()  # 引号关键字
    IF = auto()  # 如果关键字
    COND = auto()  # 条件关键字
    ELSE = auto()  # 否则关键字
    BEGIN = auto()  # 开始关键字
    SET = auto()  # 设置关键字
    LEFT_PAREN = auto()  # 左括号 (
    RIGHT_PAREN = auto()  # 右括号 )
    LEFT_BRACE = auto()  # 左大括号 {
    RIGHT_BRACE = auto()  # 右大括号 }
    COMMA = auto()  # 逗号 ,
    DOT = auto()  # 点 .
    MINUS = auto()  # 减号 -
    PLUS = auto()  # 加号 +
    SEMICOLON = auto()  # 分号 ;
    SLASH = auto()  # 斜杠 /
    STAR = auto()  # 星号 *
    BANG = auto()  # 感叹号 !
    BANG_EQUAL = auto()  # 不等于 !=
    EQUAL = auto()  # 等于 =
    EQUAL_EQUAL = auto()  # 严格等于 ==
    GREATER = auto()  # 大于 >
    GREATER_EQUAL = auto()  # 大于等于 >=
    LESS = auto()  # 小于 <
    LESS_EQUAL = auto()  # 小于等于 <=
    IDENTIFIER = auto()  # 标识符
    STRING = auto()  # 字符串
    NUMBER = auto()  # 数字
    AND = auto()  # 逻辑与 and
    OR = auto()  # 逻辑或 or
    EOF = auto()  # 文件结束符
    TRUE = auto()  # 布尔值真 true
    FALSE = auto()  # 布尔值假 false

for name, value in TokenType.__members__.items():
    _token_name_map[value] = name

def get_token_name(ttype: int) -> str:
    return _token_name_map[ttype]

class Token:
    def __init__(self, value: str, ttype: int, ln: int, offset: int):
        self.value = value
        self.ttype = ttype
        self.ln = ln
        self.offset = offset
